package android.slc.base.vmsub

import android.slc.base.api.slc.callback.SlcObserver
import android.slc.box.or.SlcCallbackConfig
import android.slc.fast.vd.wrapper.IBaseListCommonWrapper

/**
 * 此处改造暂未用上
 * 基于IBaseListCommonWrapper的拓展方法
 * @author slc
 */
fun <T> IBaseListCommonWrapper<T>.getDataListSlcObserver(
    slcCallbackConfig: SlcCallbackConfig = SlcCallbackConfig.newBuilder().showToast(false).build()
): SlcObserver<T> {
    val baseWrapper = this
    return object : SlcObserver<T>(slcCallbackConfig) {
        override fun onSucceed(data: T) {
            baseWrapper.onSucceed(data)
        }

        override fun onFailed(errorCode: Int, errorMessage: String) {
            baseWrapper.onError(errorCode, errorMessage)
        }
    }
}

/**
 * 给Java用
 */
object BaseListCommonWrapperExt {
    fun <T> getDataListSlcObserver(baseWrapper: IBaseListCommonWrapper<T>): SlcObserver<T> {
        return getDataListSlcObserver(
            baseWrapper, SlcCallbackConfig.newBuilder()
                .showToast(false).build()
        )
    }

    fun <T> getDataListSlcObserver(
        baseWrapper: IBaseListCommonWrapper<T>,
        slcCallbackConfig: SlcCallbackConfig = SlcCallbackConfig.newBuilder()
            .showToast(false).build()
    ): SlcObserver<T> {
        return object : SlcObserver<T>(slcCallbackConfig) {
            override fun onSucceed(data: T) {
                baseWrapper.onSucceed(data)
            }

            override fun onFailed(errorCode: Int, errorMessage: String) {
                baseWrapper.onError(errorCode, errorMessage)
            }
        }
    }
}